﻿/******************************************************************
** 文 件 名: Bu_WeekReport_DAL.cs
** Copyright (c) 2010-2012 Honestysoft (GuangZhou) Co.,LTD
** 创 建 人: 此代码由生成器自动生成
** 创建日期: 2012-6-9 17:21:18
** 描    述: 实现公共部分的数据访问封装，提供周报的数据访问类
** 版    本: 2.0.0.0
** 修改描述:
** 修 改 人:
** 修改日期:
******************************************************************/
using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using Honestysoft.BaseObject;
using Honestysoft.Financing.Model;

namespace Honestysoft.Financing.DataAccess
{
	/// <summary>
    /// Bu_WeekReport数据访问类
    /// </summary>
	public partial class Bu_WeekReport_DAL : BaseDataAccess<Bu_WeekReport>
    {		
		/// <summary>
        /// 构造函数，使用指定的连接字符串
        /// </summary>
        /// <param name="connectionStringName">连接字符串名称</param>
        public Bu_WeekReport_DAL(string connectionStringName)
            : base(connectionStringName)
        {

        }
        /// <summary>
        /// 得到周报
        /// </summary>
        /// <param name="year"></param>
        /// <param name="week"></param>
        /// <returns></returns>
        public Bu_WeekReport GetWeekReport(int year, int week)
        { 
            QueryParameters query = new QueryParameters();
            query.Add("TheYear",year, QueryParameters.OperatorType.Equal);
            query.Add("Week",week, QueryParameters.OperatorType.Equal);
            List<Bu_WeekReport> lsReports = SelectEntitys(query);
            if (lsReports != null && lsReports.Count == 1) { return lsReports[0]; }
            return null;
        }

        public int SaveWeekReport(string id, DateTime startDate, DateTime endDate, DateTime sendDate)
        {
            DbParameter pID = GetDbParameter("ID", id);
            DbParameter pStartDate = GetDbParameter("StartDate", startDate);
            DbParameter pEndDate = GetDbParameter("EndDate", endDate);
            DbParameter pSendDate = GetDbParameter("SendDate", sendDate);
            string sql = string.Format(@"Update Bu_WeekReport Set StartDate={0},EndDate={1},SendDate={2} Where ID={3}",
                pStartDate.ParameterName, pEndDate.ParameterName, pSendDate.ParameterName,pID.ParameterName);
            DbCommand command = GetDbCommand(sql);
            command.Parameters.Add(pID);
            command.Parameters.Add(pStartDate);
            command.Parameters.Add(pEndDate);
            command.Parameters.Add(pSendDate);
            return ExecuteNonQuery(command);
        }
    }
}
